#include "xlsxoperate.h"
#include <QDebug>
#include <QFile>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>

#include "__defines.h"
#include "data_mana.h"

XlsxOperate::XlsxOperate(QObject *parent) : QObject(parent), m_dataFlag(0), m_cliNum(1)
{

}

XlsxOperate::~XlsxOperate()
{
    xlsx->deleteLater();
}

void XlsxOperate::loadExcel(int fileFlag)
{
    if(fileFlag == 0){ // TCP
        xlsx = new QXlsx::Document("./ams/AMS_TCP.xlsx");

        m_dataFlag = 0;
    }
    else if(fileFlag == 1){ // RTU
        xlsx = new QXlsx::Document("./ams/AMS_RTU.xlsx");

        m_dataFlag = 1;
    }

    xlsx->selectSheet("Modbus信息");
    QXlsx::Worksheet* sheet_modbus = xlsx->currentWorksheet();
    if(sheet_modbus){
        int rowCount = sheet_modbus->dimension().rowCount();
        m_cliNum = rowCount - 1;

        RegisterInfo* _regInfo = new RegisterInfo();
        for(int i = 2; i <= rowCount; i++){
            for(int j = 1; j <= sheet_modbus->dimension().columnCount(); j++){
                // qDebug() << sheet_modbus->read(i, j).toString();
                if(j == 1){
                    _regInfo->slaveID = sheet_modbus->read(i, j).toUInt();
                }
                else if(j == 2){
                    _regInfo->slaveID = sheet_modbus->read(i, j).toUInt();
                }
                else if(j == 3){
                    _regInfo->slaveID = sheet_modbus->read(i, j).toUInt();
                }
                else if(j == 4){
                    _regInfo->slaveID = sheet_modbus->read(i, j).toUInt();
                }
                else if(j == 5){
                    _regInfo->slaveID = sheet_modbus->read(i, j).toUInt();
                }
            }

            Data_Mana::instance()->g_mutex.lock();
            Data_Mana::instance()->g_vecModbusInfo.push_back(_regInfo);
            Data_Mana::instance()->g_mutex.unlock();

        }
    }

    // 选择Sheet
    xlsx->selectSheet("工况点信息");
    QXlsx::Worksheet* sheet = xlsx->currentWorksheet();

    if(sheet){
        // qDebug() << sheet->dimension().rowCount() << ":" << sheet->dimension().columnCount();

        for(int i = 3; i <= sheet->dimension().rowCount(); i++){

            OperatePoint* _opePoint = new OperatePoint();
            for(int j = 1; j <= sheet->dimension().columnCount(); j++){
                // qDebug() << sheet->read(i, j).toString();

                if(j == 1){
                    _opePoint->RegisterAddr = sheet->read(i, j).toString();
                }
                else if(j == 2){
                    _opePoint->_OrderKey = sheet->read(i, j).toString();
                }
                else if(j == 3){
                    _opePoint->_DeviceKey = sheet->read(i, j).toString();
                }
                else if(j == 4){
                    _opePoint->_DeviceNameCN = sheet->read(i, j).toString();
                }
                else if(j == 5){
                    _opePoint->RegisterType = sheet->read(i, j).toString();
                }
                else if(j == 6){
                    _opePoint->RegisterCoefficient = sheet->read(i, j).toString();
                }
            }

            if(m_cliNum > 1)
            {
                if(_opePoint->RegisterType.toUInt() == RegisterType::BITS_VALUE){
                    Data_Mana::instance()->g_vecOperatePointInfo_signal.push_back(_opePoint);
                }
                else if(_opePoint->RegisterType.toUInt() == RegisterType::SWITCH_VALUE)
                {
                    Data_Mana::instance()->g_vecOperatePointInfo_switch.push_back(_opePoint);
                }
                else if(_opePoint->RegisterType.toUInt() == RegisterType::ANALOG_VALUE)
                {
                    Data_Mana::instance()->g_vecOperatePointInfo_analog.push_back(_opePoint);
                }
                else if(_opePoint->RegisterType.toUInt() == RegisterType::FLOAT_VALUE ||
                        _opePoint->RegisterType.toUInt() == RegisterType::SWAP_FLOAT ||
                        _opePoint->RegisterType.toUInt() == RegisterType::REVERSE_FLOAT)
                {
                    Data_Mana::instance()->g_vecOperatePointInfo_float.push_back(_opePoint);
                }
            }
            else{
                Data_Mana::instance()->g_mutex.lock();
                Data_Mana::instance()->g_vecOperatePointInfo.push_back(_opePoint);
                Data_Mana::instance()->g_mutex.unlock();
            }
        }
    }

    createJsonProfile();
}

bool XlsxOperate::createJsonProfile()
{
    qDebug() << "cliCount: " << m_cliNum;

    if(m_cliNum > 1)
    {
        if(m_dataFlag == 0)
        {
            createModbusCli_tcp();
        }
        else if(m_dataFlag == 1){
            createModbusCli_rtu_Multi();
        }
    }
    else
    {
        int vecSize = Data_Mana::instance()->g_vecOperatePointInfo.size();
        int cliNum = vecSize / 900;

        if(m_dataFlag == 0){
            switch (cliNum) {
            case 0:
                createModbusCli_tcp_a();
                break;
            case 1:
                createModbusCli_tcp_ab();
                break;
            case 2:
                createModbusCli_tcp_abc();
                break;
            case 3:
                createModbusCli_tcp_abcd();
                break;
            default:
                createModbusCli_tcp_a();
                break;
            }
        }
        else if(m_dataFlag == 1){
            createModbusCli_rtu();
        }
        else if(m_dataFlag == 2) //定制数据
        {

        }
    }

    return true;
}

void XlsxOperate::createModbusCli_tcp()
{
    qDebug() << "TCP";

    int vecSize_Bit = Data_Mana::instance()->g_vecOperatePointInfo_signal.size();
    int vecSize_Switch = Data_Mana::instance()->g_vecOperatePointInfo_switch.size();
    int vecSize_Analog = Data_Mana::instance()->g_vecOperatePointInfo_analog.size();
    int vecSize_Float = Data_Mana::instance()->g_vecOperatePointInfo_float.size();

    if(vecSize_Bit > 0)
    {
        // 创建一个JSON对象
        QJsonObject jsonObject;
        jsonObject["ChanCode"] = "1";
        jsonObject["ChanDesc"] = "";
        jsonObject["ChanType"] = "7";


        if(m_dataFlag == 0){
            jsonObject["DataProtocol"] = "6";
        }
        else if(m_dataFlag == 1){
            jsonObject["DataProtocol"] = "2";
        }

        // 每个工况点对应的寄存器数组
        QJsonArray jsonArray;

        QJsonObject nodeObj;
        nodeObj["DataLen"] = QString::number(vecSize_Bit);
        nodeObj["DevName"] = "1301";
        nodeObj["FunCode"] = "3";

        UINT32 regBegin = (UINT32)Data_Mana::instance()->g_vecOperatePointInfo_signal.first()->RegisterAddr.toFloat();
        nodeObj["RegisterBegin"] = QString::number(regBegin);

        QJsonArray jArray_Addr;
        for(int i = 0; i < vecSize_Bit; i++){
            QJsonObject obj_Addr;
            QString regAddr = Data_Mana::instance()->g_vecOperatePointInfo_signal.at(i)->RegisterAddr;
            obj_Addr["Addr"] = regAddr;

            int iAlias = regAddr.toFloat() * 100;

            obj_Addr["Alias"] = QString::number(iAlias);

            QString _coeffComm;
            if(Data_Mana::instance()->g_vecOperatePointInfo_signal.at(i)->RegisterCoefficient == ""){
                _coeffComm = "1";
            }
            else{
                _coeffComm = Data_Mana::instance()->g_vecOperatePointInfo_signal.at(i)->RegisterCoefficient;
            }

            QString _regType;
            if(Data_Mana::instance()->g_vecOperatePointInfo_signal.at(i)->RegisterType == ""){
                _regType = "2";
            }
            else{
                _regType = Data_Mana::instance()->g_vecOperatePointInfo_signal.at(i)->RegisterType;
            }

            int _regNum = selectRegisterType(_regType.toInt());

            QString coefficient = "0," + _coeffComm  + ",0";
            obj_Addr["Coefficient"] = coefficient;

            obj_Addr["DataTypeRegister"] = _regType;
            obj_Addr["DataLen"] = QString::number(_regNum);

            jArray_Addr.append(obj_Addr);
        }

        // 数组
        nodeObj["Results"] = jArray_Addr;
        nodeObj["SlaveId"] = "01";

        jsonArray.append(nodeObj);
        // 数组
        jsonObject["NetModTcp"] = jsonArray;
        jsonObject["WayUid"] = "1575876387";

        // 创建一个JSON文档
        QJsonDocument jsonDocument(jsonObject);

        QFile file("./config/AMS_Signal.json");
        if (file.open(QIODevice::WriteOnly))
        {
            // 将JSON文档写入文件
            file.write(jsonDocument.toJson());

            // 关闭文件
            file.close();
        }
    }

    if(vecSize_Switch > 0){
        // 创建一个JSON对象
        QJsonObject jsonObject;
        jsonObject["ChanCode"] = "1";
        jsonObject["ChanDesc"] = "";
        jsonObject["ChanType"] = "7";


        if(m_dataFlag == 0){
            jsonObject["DataProtocol"] = "6";
        }
        else if(m_dataFlag == 1){
            jsonObject["DataProtocol"] = "2";
        }

        // 每个工况点对应的寄存器数组
        QJsonArray jsonArray;

        QJsonObject nodeObj;
        nodeObj["DataLen"] = QString::number(vecSize_Bit);
        nodeObj["DevName"] = "1301";
        nodeObj["FunCode"] = "3";

        UINT32 regBegin = (UINT32)Data_Mana::instance()->g_vecOperatePointInfo_switch.first()->RegisterAddr.toFloat();
        nodeObj["RegisterBegin"] = QString::number(regBegin);

        QJsonArray jArray_Addr;
        for(int i = 0; i < vecSize_Switch; i++){
            QJsonObject obj_Addr;
            QString regAddr = Data_Mana::instance()->g_vecOperatePointInfo_switch.at(i)->RegisterAddr;
            obj_Addr["Addr"] = regAddr;

            int iAlias = regAddr.toFloat() * 100;

            obj_Addr["Alias"] = QString::number(iAlias);

            QString _coeffComm;
            if(Data_Mana::instance()->g_vecOperatePointInfo_switch.at(i)->RegisterCoefficient == ""){
                _coeffComm = "1";
            }
            else{
                _coeffComm = Data_Mana::instance()->g_vecOperatePointInfo_switch.at(i)->RegisterCoefficient;
            }

            QString _regType;
            if(Data_Mana::instance()->g_vecOperatePointInfo_switch.at(i)->RegisterType == ""){
                _regType = "2";
            }
            else{
                _regType = Data_Mana::instance()->g_vecOperatePointInfo_switch.at(i)->RegisterType;
            }

            int _regNum = selectRegisterType(_regType.toInt());

            QString coefficient = "0," + _coeffComm  + ",0";
            obj_Addr["Coefficient"] = coefficient;

            obj_Addr["DataTypeRegister"] = _regType;
            obj_Addr["DataLen"] = QString::number(_regNum);

            jArray_Addr.append(obj_Addr);
        }

        // 数组
        nodeObj["Results"] = jArray_Addr;
        nodeObj["SlaveId"] = "01";

        jsonArray.append(nodeObj);
        // 数组
        jsonObject["NetModTcp"] = jsonArray;
        jsonObject["WayUid"] = "1575876387";

        // 创建一个JSON文档
        QJsonDocument jsonDocument(jsonObject);

        QFile file("./config/AMS_Switch.json");
        if (file.open(QIODevice::WriteOnly))
        {
            // 将JSON文档写入文件
            file.write(jsonDocument.toJson());

            // 关闭文件
            file.close();
        }
    }

    if(vecSize_Analog > 0){
        // 创建一个JSON对象
        QJsonObject jsonObject;
        jsonObject["ChanCode"] = "1";
        jsonObject["ChanDesc"] = "";
        jsonObject["ChanType"] = "7";


        if(m_dataFlag == 0){
            jsonObject["DataProtocol"] = "6";
        }
        else if(m_dataFlag == 1){
            jsonObject["DataProtocol"] = "2";
        }

        // 每个工况点对应的寄存器数组
        QJsonArray jsonArray;

        QJsonObject nodeObj;
        nodeObj["DataLen"] = QString::number(vecSize_Bit);
        nodeObj["DevName"] = "1301";
        nodeObj["FunCode"] = "3";

        UINT32 regBegin = (UINT32)Data_Mana::instance()->g_vecOperatePointInfo_analog.first()->RegisterAddr.toFloat();
        nodeObj["RegisterBegin"] = QString::number(regBegin);

        QJsonArray jArray_Addr;
        for(int i = 0; i < vecSize_Analog; i++){
            QJsonObject obj_Addr;
            QString regAddr = Data_Mana::instance()->g_vecOperatePointInfo_analog.at(i)->RegisterAddr;
            obj_Addr["Addr"] = regAddr;

            int iAlias = regAddr.toFloat() * 100;

            obj_Addr["Alias"] = QString::number(iAlias);

            QString _coeffComm;
            if(Data_Mana::instance()->g_vecOperatePointInfo_analog.at(i)->RegisterCoefficient == ""){
                _coeffComm = "1";
            }
            else{
                _coeffComm = Data_Mana::instance()->g_vecOperatePointInfo_analog.at(i)->RegisterCoefficient;
            }

            QString _regType;
            if(Data_Mana::instance()->g_vecOperatePointInfo_analog.at(i)->RegisterType == ""){
                _regType = "2";
            }
            else{
                _regType = Data_Mana::instance()->g_vecOperatePointInfo_analog.at(i)->RegisterType;
            }

            int _regNum = selectRegisterType(_regType.toInt());

            QString coefficient = "0," + _coeffComm  + ",0";
            obj_Addr["Coefficient"] = coefficient;

            obj_Addr["DataTypeRegister"] = _regType;
            obj_Addr["DataLen"] = QString::number(_regNum);

            jArray_Addr.append(obj_Addr);
        }

        // 数组
        nodeObj["Results"] = jArray_Addr;
        nodeObj["SlaveId"] = "01";

        jsonArray.append(nodeObj);
        // 数组
        jsonObject["NetModTcp"] = jsonArray;
        jsonObject["WayUid"] = "1575876387";

        // 创建一个JSON文档
        QJsonDocument jsonDocument(jsonObject);

        QFile file("./config/AMS_Analog.json");
        if (file.open(QIODevice::WriteOnly))
        {
            // 将JSON文档写入文件
            file.write(jsonDocument.toJson());

            // 关闭文件
            file.close();
        }
    }

    if(vecSize_Float > 0){
        // 创建一个JSON对象
        QJsonObject jsonObject;
        jsonObject["ChanCode"] = "1";
        jsonObject["ChanDesc"] = "";
        jsonObject["ChanType"] = "7";


        if(m_dataFlag == 0){
            jsonObject["DataProtocol"] = "6";
        }
        else if(m_dataFlag == 1){
            jsonObject["DataProtocol"] = "2";
        }

        // 每个工况点对应的寄存器数组
        QJsonArray jsonArray;

        QJsonObject nodeObj;
        nodeObj["DataLen"] = QString::number(vecSize_Bit);
        nodeObj["DevName"] = "1301";
        nodeObj["FunCode"] = "3";

        UINT32 regBegin = (UINT32)Data_Mana::instance()->g_vecOperatePointInfo_float.first()->RegisterAddr.toFloat();
        nodeObj["RegisterBegin"] = QString::number(regBegin);

        QJsonArray jArray_Addr;
        for(int i = 0; i < vecSize_Float; i++){
            QJsonObject obj_Addr;
            QString regAddr = Data_Mana::instance()->g_vecOperatePointInfo_float.at(i)->RegisterAddr;
            obj_Addr["Addr"] = regAddr;

            int iAlias = regAddr.toFloat() * 100;

            obj_Addr["Alias"] = QString::number(iAlias);

            QString _coeffComm;
            if(Data_Mana::instance()->g_vecOperatePointInfo_float.at(i)->RegisterCoefficient == ""){
                _coeffComm = "1";
            }
            else{
                _coeffComm = Data_Mana::instance()->g_vecOperatePointInfo_float.at(i)->RegisterCoefficient;
            }

            QString _regType;
            if(Data_Mana::instance()->g_vecOperatePointInfo_float.at(i)->RegisterType == ""){
                _regType = "2";
            }
            else{
                _regType = Data_Mana::instance()->g_vecOperatePointInfo_float.at(i)->RegisterType;
            }

            int _regNum = selectRegisterType(_regType.toInt());

            QString coefficient = "0," + _coeffComm  + ",0";
            obj_Addr["Coefficient"] = coefficient;

            obj_Addr["DataTypeRegister"] = _regType;
            obj_Addr["DataLen"] = QString::number(_regNum);

            jArray_Addr.append(obj_Addr);
        }

        // 数组
        nodeObj["Results"] = jArray_Addr;
        nodeObj["SlaveId"] = "01";

        jsonArray.append(nodeObj);
        // 数组
        jsonObject["NetModTcp"] = jsonArray;
        jsonObject["WayUid"] = "1575876387";

        // 创建一个JSON文档
        QJsonDocument jsonDocument(jsonObject);

        QFile file("./config/AMS_Float.json");
        if (file.open(QIODevice::WriteOnly))
        {
            // 将JSON文档写入文件
            file.write(jsonDocument.toJson());

            // 关闭文件
            file.close();
        }
    }
}

void XlsxOperate::createModbusCli_tcp_a()
{
    int vecSize = Data_Mana::instance()->g_vecOperatePointInfo.size();

    // 创建一个JSON对象
    QJsonObject jsonObject;
    jsonObject["ChanCode"] = "1";
    jsonObject["ChanDesc"] = "";
    jsonObject["ChanType"] = "7";


    if(m_dataFlag == 0){
        jsonObject["DataProtocol"] = "6";
    }
    else if(m_dataFlag == 1){
        jsonObject["DataProtocol"] = "2";
    }

    // 每个工况点对应的寄存器数组
    QJsonArray jsonArray;
    // jsonObject["NetModTcp"] = QJsonArray();

    QJsonObject nodeObj;
    nodeObj["DataLen"] = QString::number(vecSize);
    nodeObj["DevName"] = "1301";
    nodeObj["FunCode"] = "3";
    nodeObj["RegisterBegin"] =  Data_Mana::instance()->g_vecOperatePointInfo.first()->RegisterAddr;

    // nodeObj["Results"] = QJsonArray();
    QJsonArray jArray_Addr;
    for(int i = 0; i < vecSize; i++){
        QJsonObject obj_Addr;
        QString regAddr = Data_Mana::instance()->g_vecOperatePointInfo.at(i)->RegisterAddr;
        obj_Addr["Addr"] = regAddr;

        obj_Addr["Alias"] = QString::number(regAddr.toDouble() * 100);

        QString _coeffComm;
        if(Data_Mana::instance()->g_vecOperatePointInfo.at(i)->RegisterCoefficient == ""){
            _coeffComm = "1";
        }
        else{
            _coeffComm = Data_Mana::instance()->g_vecOperatePointInfo.at(i)->RegisterCoefficient;
        }

        QString _regType;
        if(Data_Mana::instance()->g_vecOperatePointInfo.at(i)->RegisterType == ""){
            _regType = "2";
        }
        else{
            _regType = Data_Mana::instance()->g_vecOperatePointInfo.at(i)->RegisterType;
        }

        int _regNum = selectRegisterType(_regType.toInt());

        QString coefficient = "0," + _coeffComm  + ",0";
        obj_Addr["Coefficient"] = coefficient;

        obj_Addr["DataTypeRegister"] = _regType;
        obj_Addr["DataLen"] = QString::number(_regNum);

        jArray_Addr.append(obj_Addr);
    }

    // 数组
    nodeObj["Results"] = jArray_Addr;
    nodeObj["SlaveId"] = "01";

    jsonArray.append(nodeObj);
    // 数组
    jsonObject["NetModTcp"] = jsonArray;
    jsonObject["WayUid"] = "1575876387";

    // 创建一个JSON文档
    QJsonDocument jsonDocument(jsonObject);

    QFile file("./config/AMS1.json");
    if (file.open(QIODevice::WriteOnly))
    {
        // 将JSON文档写入文件
        file.write(jsonDocument.toJson());

        // 关闭文件
        file.close();
    }
}

void XlsxOperate::createModbusCli_tcp_ab()
{

}

void XlsxOperate::createModbusCli_tcp_abc()
{

}

void XlsxOperate::createModbusCli_tcp_abcd()
{

}

// Modbus RTU通讯方式时：只能配置一个Modbus Client
void XlsxOperate::createModbusCli_rtu()
{
    int vecSize = Data_Mana::instance()->g_vecOperatePointInfo.size();

    // 创建一个JSON对象
    QJsonObject jsonObject;
    jsonObject["ChanCode"] = "1";
    jsonObject["ChanDesc"] = "";
    jsonObject["ChanType"] = "7";


    if(m_dataFlag == 0){
        jsonObject["DataProtocol"] = "6";
    }
    else if(m_dataFlag == 1){
        jsonObject["DataProtocol"] = "2";
    }

    // 每个工况点对应的寄存器数组
    QJsonArray jsonArray;
    // jsonObject["NetModTcp"] = QJsonArray();

    QJsonObject nodeObj;
    nodeObj["DataLen"] = QString::number(vecSize);
    nodeObj["DevName"] = "1301";
    nodeObj["FunCode"] = "3";
    nodeObj["RegisterBegin"] =  Data_Mana::instance()->g_vecOperatePointInfo.first()->RegisterAddr;

    // nodeObj["Results"] = QJsonArray();
    QJsonArray jArray_Addr;
    for(int i = 0; i < vecSize; i++){
        QJsonObject obj_Addr;
        QString regAddr = Data_Mana::instance()->g_vecOperatePointInfo.at(i)->RegisterAddr;
        obj_Addr["Addr"] = regAddr;

        obj_Addr["Alias"] = QString::number(regAddr.toDouble() * 100);

        QString _coeffComm;
        if(Data_Mana::instance()->g_vecOperatePointInfo.at(i)->RegisterCoefficient == ""){
            _coeffComm = "1";
        }
        else{
            _coeffComm = Data_Mana::instance()->g_vecOperatePointInfo.at(i)->RegisterCoefficient;
        }

        QString _regType;
        if(Data_Mana::instance()->g_vecOperatePointInfo.at(i)->RegisterType == ""){
            _regType = "2";
        }
        else{
            _regType = Data_Mana::instance()->g_vecOperatePointInfo.at(i)->RegisterType;
        }

        int _regNum = selectRegisterType(_regType.toInt());

        QString coefficient = "0," + _coeffComm  + ",0";
        obj_Addr["Coefficient"] = coefficient;

        obj_Addr["DataTypeRegister"] = _regType;
        obj_Addr["DataLen"] = QString::number(_regNum);

        jArray_Addr.append(obj_Addr);
    }

    // 数组
    nodeObj["Results"] = jArray_Addr;
    nodeObj["SlaveId"] = "01";

    jsonArray.append(nodeObj);
    // 数组
    jsonObject["NetModTcp"] = jsonArray;
    jsonObject["WayUid"] = "1575876387";

    // 创建一个JSON文档
    QJsonDocument jsonDocument(jsonObject);

    QFile file("./config/AMS1.json");
    if (file.open(QIODevice::WriteOnly))
    {
        // 将JSON文档写入文件
        file.write(jsonDocument.toJson());

        // 关闭文件
        file.close();
    }
}

void XlsxOperate::createModbusCli_rtu_Multi()
{
    int vecSize_Bit = Data_Mana::instance()->g_vecOperatePointInfo_signal.size();
    int vecSize_Switch = Data_Mana::instance()->g_vecOperatePointInfo_switch.size();
    int vecSize_Analog = Data_Mana::instance()->g_vecOperatePointInfo_analog.size();
    int vecSize_Float = Data_Mana::instance()->g_vecOperatePointInfo_float.size();

    if(vecSize_Bit > 0){

    }

    if(vecSize_Switch > 0){

    }

    if(vecSize_Analog > 0){

    }

    if(vecSize_Float > 0){

    }
}

// 根据寄存器类型获取工况点对应的寄存器个数
int XlsxOperate::selectRegisterType(int type)
{
    int registerNum = 1;
    switch (type) {
    case RegisterType::BITS_VALUE:
    {
        registerNum = 1;
    }
        break;
    case RegisterType::SWITCH_VALUE:
    {
        registerNum = 1;
    }
        break;
    case RegisterType::ANALOG_VALUE:
    {
        registerNum = 1;
    }
        break;
    case RegisterType::FLOAT_VALUE:
    {
        registerNum = 2;
    }
        break;
    case RegisterType::SWAP_FLOAT:
    {
        registerNum = 2;
    }
        break;
    case RegisterType::DOUBLE_VALUE:
    {
        registerNum = 4;
    }
        break;
    case RegisterType::SWAP_DOUBLE:
    {
        registerNum = 4;
    }
        break;
    case RegisterType::REVERSE_FLOAT:
    {
        registerNum = 2;
    }
        break;
    case RegisterType::ANALOG_SIGN:
    {
        registerNum = 1;
    }
        break;

    default:
        registerNum = 1;
        break;
    }

    return registerNum;
}
